package com.ruoyi.web.controller.market.risk;

import java.util.List;
import java.util.Map;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.db.domain.RiskBaseInfo;
import com.ruoyi.risk.service.IRiskBaseInfoService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.web.wapper.RiskBaseInfoWapper;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 风控基本信息Controller
 * 
 * @author ruoyi
 * @date 2023-05-26
 */
@Controller
@RequestMapping("/risk/baseInfo")
public class RiskBaseInfoController extends BaseController
{
    private String prefix = "risk/baseInfo";

    @Autowired
    private IRiskBaseInfoService riskBaseInfoService;

    @RequiresPermissions("risk:baseInfo:view")
    @GetMapping()
    public String baseInfo()
    {
        return prefix + "/baseInfo";
    }

    /**
     * 查询风控基本信息列表
     */
    @RequiresPermissions("risk:baseInfo:view")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RiskBaseInfo riskBaseInfo)
    {
        startPage();
        List<Map<String, Object>> mapList = riskBaseInfoService.selectRiskBaseInfoListMap(riskBaseInfo);
        mapList = new RiskBaseInfoWapper(mapList).wrap();
        return getDataTable(mapList);
    }

    /**
     * 导出风控基本信息列表
     */
    @RequiresPermissions("risk:baseInfo:export")
    @Log(title = "风控基本信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RiskBaseInfo riskBaseInfo)
    {
        List<RiskBaseInfo> list = riskBaseInfoService.selectRiskBaseInfoList(riskBaseInfo);
        ExcelUtil<RiskBaseInfo> util = new ExcelUtil<RiskBaseInfo>(RiskBaseInfo.class);
        return util.exportExcel(list, "风控基本信息数据");
    }

    /**
     * 新增风控基本信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存风控基本信息
     */
    @RequiresPermissions("risk:baseInfo:add")
    @Log(title = "风控基本信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RiskBaseInfo riskBaseInfo)
    {
        return toAjax(riskBaseInfoService.insertRiskBaseInfo(riskBaseInfo));
    }

    /**
     * 修改风控基本信息
     */
    @RequiresPermissions("risk:baseInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RiskBaseInfo riskBaseInfo = riskBaseInfoService.selectRiskBaseInfoById(id);
        mmap.put("riskBaseInfo", riskBaseInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存风控基本信息
     */
    @RequiresPermissions("risk:baseInfo:edit")
    @Log(title = "风控基本信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RiskBaseInfo riskBaseInfo)
    {
        return toAjax(riskBaseInfoService.updateRiskBaseInfo(riskBaseInfo));
    }

    /**
     * 删除风控基本信息
     */
    @RequiresPermissions("risk:baseInfo:remove")
    @Log(title = "风控基本信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(riskBaseInfoService.deleteRiskBaseInfoByIds(ids));
    }
}
